<?php

class LoginController extends Controller {
	
	public $surl = NULL;
	
	public function __construct($id, $module = null) {
		$this->surl = CHtml::encode ( $_GET ['s'] );
		parent::__construct ( $id, $module );
	}
	
	public function actionIndex() {
		$model = new LoginFormA ();
		// displays the login form
		$this->render ( 'login', array ('model' => $model, 's' => $this->surl ) );
	}
	
	public function actionCheck() {
		$model = new LoginFormA ( );
		// collects user input data
		$model->attributes = $_POST ['LoginFormA'];
		
		// validates user input and redirect to previous page if validated
		if ($model->validate () && $model->authenticate ()) {
			$url = $this->surl ? $this->surl : Yii::app ()->homeUrl;
			$this->redirect ( $url );
		
		}
		DebugTool::var_dump ( $model->getErrors (), true );
		$this->redirect ( Yii::app ()->request->urlReferrer );
	}
}